import 'package:food_hub_app/models/recipe.dart';
import 'package:food_hub_app/utils/http_util.dart';
import 'package:food_hub_app/utils/index.dart';

Future<RecipeDetail> queryRecipeByIdApi(int id) {
  return HttpUtil().get<RecipeDetail>(
    "/food/recipe/$id",
    converter: (data) => RecipeDetail.fromJson(data),
  );
}

Future<bool> addRecipeApi(Recipe recipe) {
  return HttpUtil().post<bool>("/food/recipe", data: recipe);
}

Future<bool> updateRecipeApi(int id, Recipe recipe) {
  return HttpUtil().put<bool>("/food/recipe/$id", data: recipe);
}

Future<bool> deleteRecipeApi(int id) {
  return HttpUtil().delete<bool>("/food/recipe/$id");
}

Future<List<Recipe>> queryRecipeByUserApi(int id) {
  return HttpUtil().get<List<Recipe>>(
    "/food/recipe/user/$id",
    converter: (data) => convertListResponse<Recipe>(data, Recipe.fromJson),
  );
}

Future<List<Recipe>> queryRecipeUserFavouriteApi() {
  return HttpUtil().get<List<Recipe>>(
    "/food/recipe/user/favourite",
    converter: (data) => convertListResponse<Recipe>(data, Recipe.fromJson),
  );
}

Future<List<RecipeSummary>> queryRecipeApi(RecipeQuery recipeQuery) {
  return HttpUtil().get<List<RecipeSummary>>(
    "/food/recipe",
    queryParameters: recipeQuery.toJson(),
    converter: (data) => convertListResponse<RecipeSummary>(data, RecipeSummary.fromJson),
  );
}

Future<List<String>> queryFoodNameListApi() {
  return HttpUtil().get<List<String>>(
    "/food/recipe/name",
    converter:
        (data) => convertListResponse<String>(data, (json) => json.toString()),
  );
}

Future<bool> addRecordApi(Record record) {
  return HttpUtil().post<bool>("/food/record", data: record);
}

Future<bool> updateRecordApi(int id, Record record) {
  return HttpUtil().put<bool>("/food/record/$id", data: record);
}

Future<bool> deleteRecordApi(int id) {
  return HttpUtil().delete<bool>("/food/record/$id");
}

Future<bool> addRecipeCommentApi(int id, String content) {
  return HttpUtil().post<bool>("/food/recipe/$id/comment", data: content);
}

Future<bool> addRecipeLikeApi(int id) {
  return HttpUtil().post<bool>("/food/recipe/$id/like");
}

Future<bool> deleteRecipeLikeApi(int id) {
  return HttpUtil().delete<bool>("/food/recipe/$id/like");
}

Future<bool> addRecipeFavouriteApi(int id) {
  return HttpUtil().post<bool>("/food/recipe/$id/favourite");
}

Future<bool> deleteRecipeFavouriteApi(int id) {
  return HttpUtil().delete<bool>("/food/recipe/$id/like");
}

Future<List<Record>> queryRecordApi(String startDate, String endDate) {
  return HttpUtil().get<List<Record>>(
    "/food/record",
    queryParameters: {"startDate": startDate, "endDate": endDate},
    converter: (data) => convertListResponse<Record>(data, Record.fromJson),
  );
}

Future<List<String>> queryCategoryApi() {
  return HttpUtil().get<List<String>>(
    "/food/category",
    converter:
        (data) => convertListResponse<String>(data, (json) => json.toString()),
  );
}
